import stacking as sp
import cranesched as cs
# from utils.interval import Interval

##from cranesched.solvers.slidingwindow import SlidingWindow
##from cranesched.solvers.dfs import DFS
##from stacking.loader import load_from_csv, default_filter, make_cranesched
##
##
##cs = cranesched.Instance.load("error.csi")
##dfs = DFS()

####w, i, a = load_from_csv("../data/raw/large.csv", filters=[default_filter], verbose=False)
####cs = make_cranesched(w, i, a)
##cs = cranesched.Instance.load("./large.csi")
##
##def reconstruct_cs_solution(instance, assignments=None, keep_router_stack=False, verbose=False):
##    from cranesched.solution import Solution
##    
##    if assignments is None:
##        assignments = [(a.action, a.action.meta.crane) for a in instance.activities]
##        assignments.sort(key=lambda (action, _): action.id)
##        
##    action2activity = dict((a.action, a) for a in instance.activities)
##    solution = Solution(instance)
##    for action, crane_id in assignments:
##        if verbose:
##            print "%s -> %s" % (action, crane_id)
##        solution.assign(action2activity[action], solution.cranes[crane_id])
##        if not keep_router_stack:
##            solution.router.clear_stack()
##    return solution
##    
##    
##dfs = DFS(log=False)
##sw = SlidingWindow(cs, dfs, slice_size=5)

# items = [sp.Item(x) for x in "ABCD"]
# items[0].due = Interval(0, 1)
# actions = [sp.Action.pickup(0, ["B"], "S2"),
#            sp.Action.pickup(1, ["A"], "S2"),
#            sp.Action.pickup(2, ["D"], "S1"),
#            sp.Action.pickup(3, ["C"], "S1"),
#            sp.Action.putdown(4, ["A"], "S3"),
#            sp.Action.putdown(5, ["B"], "S3"),
#            sp.Action.putdown(6, ["C"], "S3"),
#            sp.Action.putdown(7, ["D"], "S3")]
# coords = {"S1": (1.0, 0.0), "S2": (2.0, 0.0), "S3": (3.0, 0.0)}
# for action in actions:
#     action.meta.xy = coords[action.place]
    
# warehouse = sp.Warehouse("foo", sp.Crane("X"))
# crane = warehouse["X"]
# crane.meta.update(initial_xy=(0.0, 0.0),
#                   capacity=4, 
#                   speed=(1.0, 1.0))

# sp_inst = sp.Instance(items, warehouse)
# sp_sol = sp.Solution(sp_inst)
# sp_sol.actions = actions
# cs_inst = cs.Instance.from_sp(sp_sol, action_duration=0.5)
# pg = cs_inst.prec_graph
# pg.show("circular")
# sol = cs.Solution(cs_inst)

# from cranesched.solvers import DFS

# dfs = DFS()
# dfs.init(cs_inst)

